package com.demo.controller;

import com.demo.entity.User;
import com.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:wesley
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public int save(){
        User user = new User();
        user.setName("test");
        user.setPass("111");
        user.setAge(111);
        user.setAddress("大连市");
        user.setMobile("15012345678");
        return userService.saveUser(user);
    }


    @RequestMapping(value = "/page",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> page(Integer pageNo, Integer pageSize){
        Map<String, Object> map = new HashMap<>();
        List<User> list = userService.pageFind(pageNo, pageSize);
        map.put("list", list);
        return map;
    }
}
